package bugtracking

/**
 * Created by IntelliJ IDEA.
 * User: alexandrua
 * Date: 6/8/11
 * Time: 4:53 PM
 * To change this template use File | Settings | File Templates.
 */
class Actor {

    String name
    String email

    static hasMany = [Bug, History]

    static constraints = {
        name(nullable: true)
        email(unique: true)
    }
    /**
     * The actor may have only email when it is used in history
     * @return the persisted object of this, if actor already exists(email used as identifier) the object will be updated,
     *
     */
    public Actor mergeActor(){

        def temp = Actor.findByEmail(email);

        if(temp != null){
            if(!temp.name){
                temp.name = name
            }
        } else {
            temp = this;
        }
        temp.save();
        return temp;
    }
}
